import React, { Component } from 'react'
import '../asserts/css/login.css'
import {login as Login} from '../request/register'

export default class login extends Component {
    state = {
        phone: "",
        password: ""
    }
    submit(){
        var sendData = {
            phone: this.state.phone,
            password: this.state.password
        }
        Login(sendData).then(res=>{
            if(res.code === 200){
                this.setState({
                    phone: "",
                    password: ""
                })
                //保存登录凭证
                localStorage.setItem('loginData',JSON.stringify(res.list))
                //跳转页面
                // console.log(this.props.history.push)
                this.props.history.push("/uncenter")

            }
        })
    }
    render() {
        var {phone,password} = this.state
        return (
            <>
                <div className="page-title">会员登录</div>
                <div className="container">
                    <div className="logo"></div>
                    <div className="form">

                        <div className="form-group">
                            <input value={phone} onChange={e=>this.setState({phone:e.target.value})} type="text" placeholder="手机号" />
                        </div>
                        <div className="form-group">
                            <input value={password} onChange={e=>this.setState({password:e.target.value})}type="password" placeholder="密码" />
                        </div>
                        <div className="form-group">
                            <button type="button" className="btn-gray" onClick={this.submit.bind(this)}>登录</button>
                        </div>
                    </div>
                </div>
            </>
        )
    }
}
